package com.ljy.cart.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

/*
* 整个购物车
*
* */

public class Cart {

    List<CartItem> items;//所有购物项
    private Integer countNum;//商品数量
    private Integer countType;//商品类型数量
    private BigDecimal totalAmount;//所有商品总价
    private BigDecimal reduce = new BigDecimal("0.00");//减免价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count=0;
        if (items != null&&items.size() > 0){
            for (CartItem item : items) {
                count+=item.getCount();
            }
        }
        return count;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    public Integer getCountType() {
        int count=0;
        if (items != null && items.size() > 0){
            for (CartItem item : items) {
                count+=1;
            }
        }
        return count;

    }



    //获取总金额
    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if (items != null && items.size() > 0){
            for (CartItem item : items){
                if (item.getCheck()){
                    BigDecimal totalPrice = item.getTotalPrice();
                    amount=amount.add(totalPrice);
                }
            }
        }
        //减掉优惠信息
        BigDecimal subtract = amount.subtract(getReduce());
        return subtract;
    }



    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }

    @Override
    public String toString() {
        return "Cart{" +
                "items=" + items +
                ", countNum=" + countNum +
                ", countType=" + countType +
                ", totalAmount=" + totalAmount +
                ", reduce=" + reduce +
                '}';
    }


    public Cart(List<CartItem> items, Integer countNum, Integer countType, BigDecimal totalAmount, BigDecimal reduce) {
        this.items = items;
        this.countNum = countNum;
        this.countType = countType;
        this.totalAmount = totalAmount;
        this.reduce = reduce;
    }


    public Cart() {
    }
}
